package com.ruoyi.eqmonitor.controller;

import java.text.SimpleDateFormat;
import java.util.List;

import com.ruoyi.eqmonitor.domain.OptHandleFlowRecord;
import com.ruoyi.eqmonitor.domain.OptPatrolTask;
import com.ruoyi.eqmonitor.dtos.OptDeviceAlarmDto;
import com.ruoyi.eqmonitor.dtos.OptPatrolRecordDto;
import com.ruoyi.eqmonitor.service.IOptHandleFlowRecordService;
import com.ruoyi.eqmonitor.service.IOptPatrolTaskService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.eqmonitor.domain.OptPatrolRecord;
import com.ruoyi.eqmonitor.service.IOptPatrolRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import java.util.Arrays;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 巡查记录
 * @author ruoyi
 * @date 2022-12-05
 */
@RestController
@RequestMapping("/patrolRecord")
public class OptPatrolRecordController extends BaseController{
    
    @Autowired
    private IOptPatrolRecordService optPatrolRecordService;


    /**
     * 巡查记录列表
     */
    @ApiOperation("巡查记录列表")
    @GetMapping("/list")
    public TableDataInfo<?> list(OptPatrolRecord optPatrolRecord){
        startPage();
        List<OptPatrolRecord> list = optPatrolRecordService.selectOptPatrolRecordList(optPatrolRecord);
        return getDataTable(list);
    }

    /**
     * 巡查记录详情
     */
    @ApiOperation("巡查记录详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(optPatrolRecordService.selectOptPatrolRecordById(id));
    }

    /**
     * 新增巡查记录
     */
    @ApiOperation("新增巡查记录")
    @Log(title = "巡查记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OptPatrolRecord optPatrolRecord){
        return toAjax(optPatrolRecordService.add(optPatrolRecord));
    }

    /**
     * 修改巡查记录
     */
    @ApiOperation("修改巡查记录")
    @PutMapping
    public AjaxResult edit(@RequestBody OptPatrolRecord optPatrolRecord){
    	optPatrolRecord.setUpdateTime(new Date());
    	optPatrolRecord.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(optPatrolRecordService.updateById(optPatrolRecord));
    }

    /**
     * 删除巡查记录
     */
    @ApiOperation("删除巡查记录")
    @Log(title = "巡查记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(optPatrolRecordService.removeByIds(Arrays.asList(ids)));
    }
    
    /**
     * 导出巡查记录列表
     */
    @ApiOperation("导出巡查记录列表")
    @Log(title = "巡查记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OptPatrolRecord optPatrolRecord){
        List<OptPatrolRecord> list = optPatrolRecordService.selectOptPatrolRecordList(optPatrolRecord);
        ExcelUtil<OptPatrolRecord> util = new ExcelUtil<OptPatrolRecord>(OptPatrolRecord.class);
        util.exportExcel(response, list, "巡查记录数据");
    }

    /**
     * 查询按片区统计巡查记录
     */
    @ApiOperation("查询按片区统计巡查记录")
    @GetMapping("/patrolStatistics")
    public AjaxResult patrolStatistics(OptPatrolRecordDto dto){
        return success(optPatrolRecordService.patrolStatistics(dto));
    }
}
